package org.crspta.gohomenotes.web;

import org.crspta.gohomenotes.domain.DismissalLocation;
import org.crspta.gohomenotes.domain.DismissalLocationType;
import org.crspta.gohomenotes.domain.Person;
import org.crspta.gohomenotes.domain.Schedule;
import org.crspta.gohomenotes.domain.SchoolClass;
import org.crspta.gohomenotes.domain.Student;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
import org.springframework.roo.addon.web.mvc.controller.converter.RooConversionService;

/**
 * A central place to register application converters and formatters. 
 */
@RooConversionService
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {

	@Override
	protected void installFormatters(FormatterRegistry registry) {
		super.installFormatters(registry);
		// Register application converters and formatters
	}
	
    public Converter<DismissalLocation, String> getDismissalLocationToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.crspta.gohomenotes.domain.DismissalLocation, java.lang.String>() {
            public String convert(DismissalLocation dismissalLocation) {
            	return new StringBuilder()
            		.append(dismissalLocation.getName())
            		.toString();
            }
        };
    }
    
    public Converter<DismissalLocationType, String> getDismissalLocationTypeToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.crspta.gohomenotes.domain.DismissalLocationType, java.lang.String>() {
            public String convert(DismissalLocationType dismissalLocationType) {
                return new StringBuilder().append(dismissalLocationType.getName()).toString();
            }
        };
    }
    
    public Converter<Schedule, String> getScheduleToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.crspta.gohomenotes.domain.Schedule, java.lang.String>() {
            public String convert(Schedule schedule) {
                return new StringBuilder()
                	.append(schedule.getSchedulePattern().getName())
                	.append(": ")
                	.append(schedule.getStartDate().toString())
                	.append(' ')
                	.append(schedule.getEndDate().toString())
                	.append(' ')
                	.append(schedule.getDescription())
                	.toString();
            }
        };
    }
    
    public Converter<SchoolClass, String> getSchoolClassToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.crspta.gohomenotes.domain.SchoolClass, java.lang.String>() {
            public String convert(SchoolClass schoolClass) {
            	return new StringBuilder().append(schoolClass.getTeacher().toString()).toString();
            }
        };
    }
    
    public Converter<Person, String> getPersonToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.crspta.gohomenotes.domain.Person, java.lang.String>() {
            public String convert(Person person) {
            	return new StringBuilder().append(person.getLastName()).append(", ").append(person.getFirstName()).toString();
            }
        };
    }
    
    public Converter<Student, String> getStudentToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.crspta.gohomenotes.domain.Student, java.lang.String>() {
            public String convert(Student student) {
            	return new StringBuilder()
            		.append(getPersonToStringConverter().convert(student.getPerson()))
            		.append(" (")
            		.append(getSchoolClassToStringConverter().convert(student.getSchoolClass()))
            		.append(" )")
            		.toString();
            }
        };
    }
     
}
